import axios from "axios"
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

axios.interceptors.request.use(function (config) {
  return config;
}, function (error) {
  return Promise.reject(error);
});

axios.interceptors.response.use(function (response) {
  return response;
}, function (error) {
  return Promise.reject(error);
});

export function get(url, params, headers) {
  return new Promise(function (resolve, reject) {
    axios.get(url, {
      params,
      headers,
    }).then(res => {
      resolve(res.data);
    }).catch(err => {
      reject(err);
    })
  })
}

export function post(url, body, headers) {
  return new Promise(function (resolve, reject) {
    axios.post(url, body, {
      headers,
    }).then(res => {
      resolve(res.data);
    }).catch(err => {
      reject(err);
    })
  })
}

export function patch(url, data, headers) {
  return new Promise(function (resolve, reject) {
    axios.patch(url, data, {
      headers
    }).then(res => {
      resolve(res.data);
    }).catch(err => {
      reject(err);
    })
  })
}

export function Delete(url, body, headers) {
  return new Promise(function (resolve, reject) {
    axios.delete(url, body, {
      headers,
    }).then(res => {
      resolve(res.data);
    }).catch(err => {
      reject(err);
    })
  })
}

export {
  axios
}